# 954 中等：二倍数对数组
from collections import Counter


class Solution:
    # def canReorderDoubled(self, arr: List[int]) -> bool:
    def canReorderDoubled(self, arr) -> bool:
        # Counter类
        cnt = Counter(arr)
        # 按绝对值排序
        # print(sorted(cnt, key=abs))
        if cnt[0] % 2:
            return False
        for i in sorted(cnt, key=abs):
            if cnt[2 * i] < cnt[i]:
                return False
            cnt[2 * i] -= cnt[i]
        return True


s = Solution()
print(s.canReorderDoubled([3, 1, 3, 6]))
print(s.canReorderDoubled([2, 1, 2, 6]))
print(s.canReorderDoubled([4, -2, 2, -4]))
